package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.OrderOperateInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailAllPriceInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailFreightInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailFreightTipInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailLineInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailOperateInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailPictureInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailRemarkInfo;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.DetailAllPriceViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.DetailLineViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.DetailRemarkViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.SaleCarFreightViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.SaleCarOperateViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.SaleCarPictureViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.SaleCarTipViewHolder;
import com.tianhui.consignortwofei.mvp.ui.viewHolder.detail.SaleCarViewHolder;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2020/8/26
 * @description
 **/
public class SaleCarAdapter extends RecyclerArrayAdapter {

    private static final int TYPE_ITEM_NORMAL = 1;
    private static final int TYPE_ITEM_PICTURE = 2;
    private static final int TYPE_ITEM_REMARK = 3;
    private static final int TYPE_ITEM_OPERATE = 4;
    private static final int TYPE_ITEM_FREIGHT = 5;
    private static final int TYPE_ITEM_FREIGHT_TIP = 6;
    private static final int TYPE_ITEM_LINE = 7;
    private static final int TYPE_All_PRICE = 8;

    private OnDetailOperateItemClickListener onDetailOperateItemClickListener;
    private OnFreightInputItemListener onFreightInputItemListener;

    @Override
    public int getViewType(int position) {
        Object object = getItem(position);
        if (object instanceof DetailInfo) {
            return TYPE_ITEM_NORMAL;
        } else if (object instanceof DetailRemarkInfo) {
            return TYPE_ITEM_REMARK;
        } else if (object instanceof DetailOperateInfo) {
            return TYPE_ITEM_OPERATE;
        } else if (object instanceof DetailPictureInfo) {
            return TYPE_ITEM_PICTURE;
        } else if (object instanceof DetailFreightInfo) {
            return TYPE_ITEM_FREIGHT;
        } else if (object instanceof DetailFreightTipInfo) {
            return TYPE_ITEM_FREIGHT_TIP;
        } else if (object instanceof DetailLineInfo) {
            return TYPE_ITEM_LINE;
        } else if (object instanceof DetailAllPriceInfo) {
            return TYPE_All_PRICE;
        }
        return super.getViewType(position);
    }

    public SaleCarAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_ITEM_NORMAL:
                return new SaleCarViewHolder(parent, R.layout.item_salecar_detail);
            case TYPE_ITEM_REMARK:
                return new DetailRemarkViewHolder(parent, R.layout.item_detail_remark);
            case TYPE_ITEM_OPERATE:
                return new SaleCarOperateViewHolder(parent, R.layout.item_detail_operate, onDetailOperateItemClickListener);
            case TYPE_ITEM_PICTURE:
                return new SaleCarPictureViewHolder(parent, R.layout.item_sale_car_picture, onDetailOperateItemClickListener);
            case TYPE_ITEM_FREIGHT:
                return new SaleCarFreightViewHolder(parent, R.layout.item_detail_freight, onFreightInputItemListener);
            case TYPE_ITEM_FREIGHT_TIP:
                return new SaleCarTipViewHolder(parent, R.layout.item_sale_car_tip);
            case TYPE_ITEM_LINE:
                return new DetailLineViewHolder(parent, R.layout.item_detail_line);
            case TYPE_All_PRICE:
                return new DetailAllPriceViewHolder(parent, R.layout.item_all_price);
        }
        return null;
    }

    //订单详情底部操作
    public interface OnDetailOperateItemClickListener {
        void onOperateClick(int position, OrderOperateInfo orderOperateInfo);
    }

    public void setOnDetailOperateItemClickListener(OnDetailOperateItemClickListener onDetailOperateItemClickListener) {
        this.onDetailOperateItemClickListener = onDetailOperateItemClickListener;
    }

    public interface OnFreightInputItemListener {
        void onInput(String goodsPrice, String price, String grants, String otherPrice, String zhuangChePrice, String cangChuPrice);

        void onRemarkInput(String grantsRemark, String deductRemark);


    }

    public void setOnFreightInputItemListener(OnFreightInputItemListener onFreightInputItemListener) {
        this.onFreightInputItemListener = onFreightInputItemListener;
    }

}
